﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AIMLbot;
using ChatBuddy.Classes.Chat.Helpers;
using ChatBuddy.Classes.Chat.Processor;
using ChatBuddy.Classes.Helpers;
using ChatBuddy.Classes.Helpers.Friend_Helper;
using ChatBuddy.Classes.Helpers.Guild_Helper;
using ChatBuddy.Forms.Primary.SettingsWindow;
using Styx;
using Styx.CommonBot;
using Styx.Plugins;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace ChatBuddy
{
    class ChatBuddy : HBPlugin
    {
        private static LocalPlayer Me { get { return StyxWoW.Me; } }
        private Bot Alice;
        private User User;
        private static readonly SettingsHelper SettingsHelper = new SettingsHelper();
        private static List<FriendMember> _friendMembers;
        private static List<FriendMember> _bFriendMembers;
        private static List<GuildMember> _guildMembers; 

        public override void Pulse()
        {
            // throw new NotImplementedException();
        }

        public override string Name
        {
            get { return "ChatBuddy"; }
        }

        public override string Author
        {
            get { return "Ronald L. Harsh"; }
        }

        public override Version Version
        {
            get { return new Version(1,0,1,0);}
        }

        public override bool WantButton
        {
            get { return true; }
        }

        public override string ButtonText
        {
            get { return "Settings"; }
        }

        public override void OnButtonPress()
        {
            try
            {
                var s = new SettingsWindow();
                s.Show();
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
            }
        }

        public override void OnEnable()
        {
            StartListening();
        }

        public override void OnDisable()
        {
            Lua.Events.DetachEvent("CHAT_MSG_WHISPER", ChatHelper.ChatWhisper);
        }

        public static void StartListening()
        {
            try
            {
                ChatHelper.InitializeAlice();
                SettingsHelper.Initialize();
                ChatHelper.SettingsHelper = SettingsHelper;

                _friendMembers = new List<FriendMember>();
                _friendMembers = new FriendLister().GetOoFriendMembers();
                _bFriendMembers = new List<FriendMember>();
                _bFriendMembers = new FriendLister().GetBnetFriends();
                _guildMembers = new List<GuildMember>();
                _guildMembers = new GuildLister().GetGuildies();

                ChatHelper._bFriendMembers = _bFriendMembers;
                ChatHelper._friendMembers = _friendMembers;
                ChatHelper._guildMembers = _guildMembers;

                //Lua.Events.AttachEvent("CHAT_MSG_SAY", Helper.bn);
                Lua.Events.AttachEvent("CHAT_MSG_GUILD", ChatHelper.bn);
                Lua.Events.AttachEvent("CHAT_MSG_WHISPER", ChatHelper.ChatWhisper);
                //Lua.Events.AttachEvent("CHAT_MSG_EMOTE", Helper.bn);
                //Lua.Events.AttachEvent("CHAT_MSG_TEXT_EMOTE", Helper.bn);
                Lua.Events.AttachEvent("PLAYER_DEAD", ChatHelper.PlayerDied);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
            }
        }
    }
}
